// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <fmt/format.h>
#include <melon/compression/compression.h>
#include <string>

namespace kumo::pollux::common {
    enum CompressionKind {
        CompressionKind_NONE = 0,
        CompressionKind_ZLIB = 1,
        CompressionKind_SNAPPY = 2,
        CompressionKind_LZO = 3,
        CompressionKind_ZSTD = 4,
        CompressionKind_LZ4 = 5,
        CompressionKind_GZIP = 6,
        CompressionKind_MAX = INT64_MAX
    };

    std::unique_ptr<melon::compression::Codec> compressionKindToCodec(
        CompressionKind kind);

    CompressionKind codecTypeToCompressionKind(melon::compression::CodecType type);

    /// Get the name of the CompressionKind.
    std::string compressionKindToString(CompressionKind kind);

    CompressionKind stringToCompressionKind(const std::string &kind);

    constexpr uint64_t DEFAULT_COMPRESSION_BLOCK_SIZE = 256 * 1024;
} // namespace kumo::pollux::common

template<>
struct fmt::formatter<kumo::pollux::common::CompressionKind>
        : fmt::formatter<std::string> {
    auto format(
        const kumo::pollux::common::CompressionKind &s,
        format_context &ctx) const {
        return formatter<std::string>::format(
            kumo::pollux::common::compressionKindToString(s), ctx);
    }
};
